//
//  Pay_View.m
//  MZJ
//
//  Created by XDD on 16/6/25.
//  Copyright © 2016年 XDD. All rights reserved.
//

#import "Pay_View.h"

@interface Pay_View () {
    
    NSArray *nameArr;
    UIView *view;
    
    //    NSArray *cityArr;
    NSInteger page;
    //    NSMutableArray *cityArrays;
    NSArray *btnTitles;
    UIButton *aBt;
    UIView *view1;
}

@end

@implementation Pay_View

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initializeView];
    }
    return self;
}

- (void)initializeView {
    _mBview_pay = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    _mBview_pay.backgroundColor = [self colorWithHexString:@"000000" withAlpha:0.75];
    [self addSubview:_mBview_pay];
    
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapClickAction:)];
    [_mBview_pay addGestureRecognizer:singleTap];
    
    
    _paytype_View = [[UIView alloc]initWithFrame:CGRectMake(60, kHeight/3 - 20, kWidth - 120, 0)];
    _paytype_View.layer.cornerRadius = 4.0;
    _paytype_View.layer.masksToBounds = YES;
    _paytype_View.backgroundColor = [UIColor whiteColor];
    [self addSubview:_paytype_View];
    
    UILabel *pay_type = [[UILabel alloc]initWithFrame:CGRectMake(15, 5, 100, 40)];
    pay_type.text = @"付款方式";
    pay_type.textAlignment = NSTextAlignmentLeft;
    pay_type.font = [UIFont systemFontOfSize:13];
    pay_type.textColor = [UIColor orangeColor];
    [_paytype_View addSubview:pay_type];
    
    UIView *lines1 = [[UIView alloc]initWithFrame:CGRectMake(15, 50, _paytype_View.frame.size.width - 30, 1)];
    lines1.backgroundColor = [UIColor lightGrayColor];
    [_paytype_View addSubview:lines1];
    
    UIButton *wx_Button = [UIButton buttonWithType:UIButtonTypeCustom];
    wx_Button.backgroundColor = [UIColor clearColor];
    [wx_Button addTarget:self action:@selector(wx_ButtonAction) forControlEvents:UIControlEventTouchUpInside];
    wx_Button.frame = CGRectMake(15, 51, _paytype_View.frame.size.width - 30, 40);
    [_paytype_View addSubview:wx_Button];
    
    UIImageView *wx_ImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 7, 26, 26)];
//    wx_ImageView.backgroundColor = [UIColor purpleColor];
    wx_ImageView.image = [UIImage imageNamed:@"weixin_img"];
    [wx_Button addSubview:wx_ImageView];
    
    UILabel *wx_Label = [[UILabel alloc]initWithFrame:CGRectMake(35, 10, 100, 20)];
    wx_Label.text = @"微信支付";
    wx_Label.font = [UIFont systemFontOfSize:13];
    wx_Label.textAlignment = NSTextAlignmentLeft;
    wx_Label.textColor = [UIColor grayColor];
    [wx_Button addSubview:wx_Label];
    
    _wx_ImageView_choose = [[UIImageView alloc]initWithFrame:CGRectMake(_paytype_View.frame.size.width - 46, 15, 16, 16)];
//    _wx_ImageView_choose.backgroundColor = [UIColor purpleColor];
    _wx_ImageView_choose.image = [UIImage imageNamed:@"iconfont-gouxuan_img"];
    [wx_Button addSubview:_wx_ImageView_choose];
    
    UIView *lines2 = [[UIView alloc]initWithFrame:CGRectMake(15, 91, _paytype_View.frame.size.width - 30, 1)];
    lines2.backgroundColor = [UIColor lightGrayColor];
    [_paytype_View addSubview:lines2];
    
    UIButton *zfb_Button = [UIButton buttonWithType:UIButtonTypeCustom];
    zfb_Button.backgroundColor = [UIColor clearColor];
    [zfb_Button addTarget:self action:@selector(zfb_ButtonAction) forControlEvents:UIControlEventTouchUpInside];
    zfb_Button.frame = CGRectMake(15, 92, _paytype_View.frame.size.width - 30, 40);
    [_paytype_View addSubview:zfb_Button];
    
    UIImageView *xfb_ImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 7, 26, 26)];
    xfb_ImageView.image = [UIImage imageNamed:@"zhifubao_img"];

//    xfb_ImageView.backgroundColor = [UIColor purpleColor];
    [zfb_Button addSubview:xfb_ImageView];
    
    UILabel *zfb_Label = [[UILabel alloc]initWithFrame:CGRectMake(35, 10, 100, 20)];
    zfb_Label.text = @"支付宝支付";
    zfb_Label.font = [UIFont systemFontOfSize:13];
    zfb_Label.textAlignment = NSTextAlignmentLeft;
    zfb_Label.textColor = [UIColor grayColor];
    [zfb_Button addSubview:zfb_Label];
    
    _zfb_ImageView_choose = [[UIImageView alloc]initWithFrame:CGRectMake(_paytype_View.frame.size.width - 46, 15, 16, 16)];
//    _zfb_ImageView_choose.backgroundColor = [UIColor purpleColor];
    _zfb_ImageView_choose.image = [UIImage imageNamed:@"Checked-NO_img@2x"];
    [zfb_Button addSubview:_zfb_ImageView_choose];
    
    UIView *lines3 = [[UIView alloc]initWithFrame:CGRectMake(15, 132, _paytype_View.frame.size.width - 30, 1)];
    lines3.backgroundColor = [UIColor lightGrayColor];
    [_paytype_View addSubview:lines3];
    
    UIButton *yl_Button = [UIButton buttonWithType:UIButtonTypeCustom];
    yl_Button.backgroundColor = [UIColor clearColor];
    [yl_Button addTarget:self action:@selector(yl_ButtonAction) forControlEvents:UIControlEventTouchUpInside];
    yl_Button.frame = CGRectMake(15, 133, _paytype_View.frame.size.width - 30, 40);
    [_paytype_View addSubview:yl_Button];
    
    UIImageView *yl_ImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 7, 26, 26)];
//    yl_ImageView.backgroundColor = [UIColor purpleColor];
    yl_ImageView.image = [UIImage imageNamed:@"yinlian_img"];
    [yl_Button addSubview:yl_ImageView];
    
    UILabel *yl_Label = [[UILabel alloc]initWithFrame:CGRectMake(35, 10, 100, 20)];
    yl_Label.text = @"银联支付";
    yl_Label.font = [UIFont systemFontOfSize:13];
    yl_Label.textAlignment = NSTextAlignmentLeft;
    yl_Label.textColor = [UIColor grayColor];
    [yl_Button addSubview:yl_Label];
    
    _yl_ImageView_choose = [[UIImageView alloc]initWithFrame:CGRectMake(_paytype_View.frame.size.width - 46, 15, 16, 16)];
//    _yl_ImageView_choose.backgroundColor = [UIColor purpleColor];
    _yl_ImageView_choose.image = [UIImage imageNamed:@"Checked-NO_img@2x"];
    [yl_Button addSubview:_yl_ImageView_choose];
    
    UIView *lines4 = [[UIView alloc]initWithFrame:CGRectMake(15, 173, _paytype_View.frame.size.width - 30, 1)];
    lines4.backgroundColor = [UIColor lightGrayColor];
    [_paytype_View addSubview:lines4];
    
    UIButton *quxiaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quxiaoBtn.frame = CGRectMake(_paytype_View.frame.size.width/7, 208, _paytype_View.frame.size.width*2/7, 30);
    [quxiaoBtn setTitle:@"取消" forState:UIControlStateNormal];
    quxiaoBtn.layer.borderWidth = 1.0;
    quxiaoBtn.layer.cornerRadius = 15.0;
    quxiaoBtn.layer.masksToBounds = YES;
    [quxiaoBtn addTarget:self action:@selector(quxiaoBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [quxiaoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    quxiaoBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_paytype_View addSubview:quxiaoBtn];
    
    UIButton *pay_Btn = [UIButton buttonWithType:UIButtonTypeCustom];
    pay_Btn.frame = CGRectMake(_paytype_View.frame.size.width*4/7, 208, _paytype_View.frame.size.width*2/7, 30);
    [pay_Btn setTitle:@"立即支付" forState:UIControlStateNormal];
//    pay_Btn.layer.borderWidth = 1.0;
    pay_Btn.layer.cornerRadius = 15.0;
    pay_Btn.layer.masksToBounds = YES;
    [pay_Btn addTarget:self action:@selector(pay_BtnAction) forControlEvents:UIControlEventTouchUpInside];
    pay_Btn.backgroundColor = [UIColor colorWithRed:253/255.0 green:179/255.0 blue:10/255.0 alpha:1];
    pay_Btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_paytype_View addSubview:pay_Btn];
}

- (void)animationHidden {
    
    
}

- (void)quxiaoBtnAction {
    if (self.didquxiaoBtnActionBlock) {
        self.didquxiaoBtnActionBlock();
    }
}

- (void)pay_BtnAction {
    if (self.didpay_BtnActionBlock) {
        self.didpay_BtnActionBlock();
    }
}

- (void)wx_ButtonAction {
    if (self.didwx_ButtonActionBlock) {
        self.didwx_ButtonActionBlock();
    }
}

- (void)zfb_ButtonAction {
    if (self.didzfb_ButtonActionBlock) {
        self.didzfb_ButtonActionBlock();
    }
}

- (void)yl_ButtonAction {
    if (self.didyl_ButtonActionBlock) {
        self.didyl_ButtonActionBlock();
    }
}

- (IBAction)singleTapClickAction:(id)sender {
    //    [view removeFromSuperview];
    if (self.didsingleTapClickActionBlock) {
        self.didsingleTapClickActionBlock();
    }
}

- (UIColor *) colorWithHexString: (NSString *)color withAlpha:(double)alpha {
    
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:alpha];
}


@end
